package wechat.handler.request.base;

import com.alibaba.fastjson.JSONObject;

import wechat.handler.util.http.HttpClientUtil;

public class BaseTemplate extends BaseRequest{
	
	protected boolean setIndustry(String param) throws Exception {
		String url = super.api_set_industry.replace("ACCESS_TOKEN", getAccessToken());
		String result = HttpClientUtil.post(url, param);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return true;
	}
	
	protected boolean setIndustry(String appid,String param) throws Exception {
		String url = super.api_set_industry.replace("ACCESS_TOKEN", getAccessToken(appid));
		String result = HttpClientUtil.post(url, param);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return true;
	}
	
	protected String addTemplate(String templateIdShort) throws Exception {
		String url = super.api_add_template.replace("ACCESS_TOKEN", getAccessToken());
		String result = HttpClientUtil.post(url, templateIdShort);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return jsonResult.getString("template_id");
	}
	
	protected String addTemplate(String appid,String templateIdShort) throws Exception {
		String url = super.api_add_template.replace("ACCESS_TOKEN", getAccessToken(appid));
		String result = HttpClientUtil.post(url, templateIdShort);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return jsonResult.getString("template_id");
	}
	
	protected String getAllTemplate() throws Exception {
		String url = super.api_all_template.replace("ACCESS_TOKEN", getAccessToken());
		String result = HttpClientUtil.get(url);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return jsonResult.getString("template_list");
	}
	
	protected String getAllTemplate(String appid) throws Exception {
		String url = super.api_all_template.replace("ACCESS_TOKEN", getAccessToken(appid));
		String result = HttpClientUtil.get(url);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return jsonResult.getString("template_list");
	}
	
	protected boolean sendTemplate(String param) throws Exception {
		String url = super.api_send_template.replace("ACCESS_TOKEN", getAccessToken());
		String result = HttpClientUtil.post(url, param);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return true;
	}
	
	protected boolean sendTemplate(String appid ,String param) throws Exception {
		String url = super.api_send_template.replace("ACCESS_TOKEN", getAccessToken(appid));
		String result = HttpClientUtil.post(url, param);
		
		JSONObject jsonResult = JSONObject.parseObject(result);
		checkResult(jsonResult);
			
		return true;
	}
}
